<?php
namespace App\Modules\Menu;
use App\Modules\AdapterApi;
use App\Services\User\UserIndex;
/**
 * Created by PhpStorm.
 * User: 97606
 * Date: 2018/6/12
 * Time: 10:10
 */
class AdminMenu extends AdapterApi
{
    // 根据角色获取后台菜单
    public function get(): array
    {
        $data = pick_array($this->postData, ['token']);
        return UserIndex::Menu()->treeByAppKey($data);
    }
    // 为某一角色增加某一菜单及其子菜单的(展示权限) 仅是可展示,该菜单及其子菜单的功能能否被访问,取决于权限是否被允许
    public function addShowMenuAndChildren(): array
    {
         $data = pick_array($this->postData, ['role_id','menu_id']);
        return UserIndex::Menu()->addShowMenuAndChildren($data);
    }
    // 为某一角色增加某一菜单的(展示权限) 仅是可展示,该菜单的功能能否被访问,取决于权限是否被允许
    public function addShowMenuAuthByRole(): array
    {
         $data = pick_array($this->postData, ['role_id','menu_id']);
        return UserIndex::Menu()->addShowMenuAuthByRole($data);
    }
    // 增加一个非顶级菜单
    public function add(): array
    {
         $data = pick_array($this->postData, ['menu_cate_id','name','name_cn','order','type','url','merge_auth','auth_data','auth_id','pid','level']);
        return UserIndex::Menu()->add($data);
    }
    // 创建顶级菜单
    public function addTop(): array
    {
        $data = pick_array($this->postData, ['menu_cate_id','name','name_cn','order','type','url','merge_auth','auth_data','auth_id']);
        return UserIndex::Menu()->addTop($data);
    }
    // 停止某一角色某一菜单的(展示权限)
    public function stopShowMenuAuthByRole(): array
    {
        $data = pick_array($this->postData, ['id','role_id','menu_id']);
        return UserIndex::Menu()->stopShowMenuAuthByRole($data);
    }
    // 启用某一角色某一菜单的(展示权限)
    public function startShowMenuAuthByRole(): array
    {
        $data = pick_array($this->postData, ['id','role_id','menu_id']);
        return UserIndex::Menu()->startShowMenuAuthByRole($data);
    }
    // 获取某一菜单分类下的菜单树
    public function treeByCate(): array
    {
        $data = pick_array($this->postData, ['menu_cate_id']);
        return UserIndex::Menu()->treeByCate($data);
    }
    // 移动某一菜单记录及其子记录到另一记录下
    public function move(): array
    {
        $data = pick_array($this->postData, ['id','pid']);
        return UserIndex::Menu()->move($data);
    }
    // 停止某一角色某一菜单及其可用子菜单的(展示权限)
    public function stopShowMenuAndChildren(): array
    {
        $data = pick_array($this->postData, ['id','role_id','menu_id']);
        return UserIndex::Menu()->stopShowMenuAndChildren($data);
    }
    // 启用某一角色某一菜单及其可用子菜单的(展示权限)
    public function startShowMenuAndChildren(): array
    {
        $data = pick_array($this->postData, ['id','role_id','menu_id']);
        return UserIndex::Menu()->startShowMenuAndChildren($data);
    }
        // 编辑某一菜单记录
    public function edit(): array
    {
        $data = pick_array($this->postData, ['id','name','name_cn','menu_cate_id','pid','order','level']);
        return UserIndex::Menu()->edit($data);
    }

}